Various encoding schemes are known for encoding a video or sequence of pictures. The video may include a plurality of pictures, each picture sub-divided into a plurality of slices. Each slice includes a plurality of 8×8 pixel blocks. For example, encoding schemes may be discrete cosine transform-(“DCT”) based, which transforms blocks into 8×8 matrices of coefficients. The DCT coefficient matrix for each block is then quantized with a quantizer parameter, reducing some coefficients to zero. The quantized coefficient matrix is scanned in a pre-defined pattern, and the result is stored in a one-dimensional array.
The one-dimensional array is encoded with standard run-level encoding, where each group of consecutive zeros and subsequent non-zero value in the array is replaced with a run-level code. Additional encoding may be applied, resulting in a bit stream. The bit stream can be transmitted and decoded into a sequence of pictures similar to the encoded sequence of pictures. Because coefficients were quantized in the quantization step, some picture information is lost and not recovered in the decoding process.
Entropy encoders are known in the art. For example, Golomb-Rice and exponential Golomb codes are families of entropy codes that are indexed by a non-negative integer value (called an “order”). Both code families include non-negative integers as their symbol alphabets. Furthermore, both code families output codewords consisting of three parts: a unary prefix consisting solely of zero bits, a separator consisting of a single one bit and a binary suffix. If the prefix has q bits, the separator is a single bit and the suffix is k bits, the length of an individual code is q+k+1.
To encode a non-negative integer n using a Golomb-Rice code of order k, known coders first calculate the quotient and remainder of n with respect to 2k, q=floor(n/2k) and r=n mod 2k. These calculations are trivial: r corresponds to the k least-significant bits of the binary representation of n, and q corresponds to the other, most-significant, bits. Then the codeword for n consists of q zero bits, a single one bit, and k bits containing the binary representation of r; the length of the codeword is clearly q+1+k.
The exponential Golomb codes have a slightly more complex structure. For these the number of zero bits in the code prefix is q=floor(log2(n+2k))−k, where again n is a non-negative integer being encoded and k is the code order. The length of the suffix is q+k. As it happens, rather than specifying its suffix, the codeword is most easily obtained directly as the binary representation of the sum n+2k, zero-extended by q bits for a total codeword length of q+1+q+k=2q+k+1. In these calculations, floor(log2(n+2k)) is not difficult to compute; if the minimal-length binary representation of n+2k requires b bits, then floor(log2(n+2k)) is simply b−1.
Golomb-Rice codes and exponential Golomb codes are each well-suited for distinct source distributions. However, a need exists for a structured coding scheme that can efficiently encode source distributions that cannot be efficiently encoded by either Golomb-Rice or exponential Golomb codes.